package com.qf.common.handler;

import com.qf.common.ex.BaseException;
import com.qf.common.result.ResponseResult;
import com.qf.common.result.ResponseResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.rmi.ServerException;

@RestControllerAdvice
@Slf4j
public class GlobalHandlerException {

    @ExceptionHandler(Exception.class)
    public ResponseResult<Object> handler(Exception ex) {
        log.error(ex.getMessage());
        return ResponseResult.error(ResponseResultCode.SYS_ERROR);
    }

    @ExceptionHandler({ServerException.class, BaseException.class})
    public ResponseResult<Object> handler(BaseException baseException) {
        log.error(baseException.getMessage());
        return ResponseResult.error(baseException.getResponseResultCode());
    }

}
